import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
import { SurveyService } from './survey.service';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
import { ModuleSwaggerTags } from '~/constants/modules.constant';
import { CreateSurveyDto } from './survey.dto';
import { AllowAnon } from '../auth/decorators/allow-anon.decorator';
import { Public } from '../auth/decorators/public.decorator';

@ApiTags(ModuleSwaggerTags.SURVEY)
@ApiBearerAuth()
@Controller('cms/qnaire')
export class SurveyController {
  constructor(private readonly surveyService: SurveyService) {}

	@AllowAnon()
  @Post()
  @ApiOperation({ summary: '创建问卷' })
  @ApiBody({ type: CreateSurveyDto })
  async createSurvey(@Body() dto: CreateSurveyDto) {
    return await this.surveyService.save(dto);
  }

  // 删除问卷/测试
  @Delete(':id')
  @ApiOperation({ summary: '删除问卷' })
  async deleteSurvey(@Param('id') pageId: string) {
		await this.surveyService.removeByPageId(pageId);
	}

	@Public()
	@Get('detail/:id')
	@ApiOperation({ summary: '获取问卷详情' })
	async getSurvey(@Param('id') pageId: string) {
		return await this.surveyService.findByPageId(pageId);
	}
}
